/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package ormsamples;

import org.orm.*;
public class RetrieveAndUpdatePinPassData {
	public void retrieveAndUpdateTestData() throws PersistentException {
		PersistentTransaction t = orm.PinPassPersistentManager.instance().getSession().beginTransaction();
		try {
			orm.DAOFactory lDAOFactory = orm.DAOFactory.getDAOFactory();
			orm.dao.TarjetaDAO oRMTarjetaDAO = lDAOFactory.getTarjetaDAO();
			orm.Tarjeta oRMTarjeta = oRMTarjetaDAO.loadTarjetaByQuery(null, null);
			// Update the properties of the persistent object
			oRMTarjetaDAO.save(oRMTarjeta);
			orm.dao.ClienteDAO oRMClienteDAO = lDAOFactory.getClienteDAO();
			orm.Cliente oRMCliente = oRMClienteDAO.loadClienteByQuery(null, null);
			// Update the properties of the persistent object
			oRMClienteDAO.save(oRMCliente);
			orm.dao.CoordenadaDAO oRMCoordenadaDAO = lDAOFactory.getCoordenadaDAO();
			orm.Coordenada oRMCoordenada = oRMCoordenadaDAO.loadCoordenadaByQuery(null, null);
			// Update the properties of the persistent object
			oRMCoordenadaDAO.save(oRMCoordenada);
			t.commit();
		}
		catch (Exception e) {
			t.rollback();
		}
		
	}
	
	public void retrieveByCriteria() throws PersistentException {
		System.out.println("Retrieving Tarjeta by TarjetaCriteria");
		orm.TarjetaCriteria tarjetaCriteria = new orm.TarjetaCriteria();
		// Please uncomment the follow line and fill in parameter(s)
		//tarjetaCriteria.id.eq();
		System.out.println(tarjetaCriteria.uniqueTarjeta());
		
		System.out.println("Retrieving Cliente by ClienteCriteria");
		orm.ClienteCriteria clienteCriteria = new orm.ClienteCriteria();
		// Please uncomment the follow line and fill in parameter(s)
		//clienteCriteria.id.eq();
		System.out.println(clienteCriteria.uniqueCliente());
		
		System.out.println("Retrieving Coordenada by CoordenadaCriteria");
		orm.CoordenadaCriteria coordenadaCriteria = new orm.CoordenadaCriteria();
		// Please uncomment the follow line and fill in parameter(s)
		//coordenadaCriteria.id.eq();
		System.out.println(coordenadaCriteria.uniqueCoordenada());
		
	}
	
	
	public static void main(String[] args) {
		try {
			RetrieveAndUpdatePinPassData retrieveAndUpdatePinPassData = new RetrieveAndUpdatePinPassData();
			try {
				retrieveAndUpdatePinPassData.retrieveAndUpdateTestData();
				//retrieveAndUpdatePinPassData.retrieveByCriteria();
			}
			finally {
				orm.PinPassPersistentManager.instance().disposePersistentManager();
			}
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}
